package cn.hk.message.service.impl;

import cn.hk.message.domain.Message;
import cn.hk.message.domain.MessageCopy20220720;
import cn.hk.message.mapper.MessageCopy20220720Mapper;
import cn.hk.message.service.MessageCopy20220720Service;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 消息推送信息表 服务实现类
 * </p>
 *
 * @author xu
 * @since 2023-03-08
 */
@Service
public class MessageCopy20220720ServiceImpl extends ServiceImpl<MessageCopy20220720Mapper, MessageCopy20220720> implements MessageCopy20220720Service {

    @Autowired
    private MessageCopy20220720Mapper messageCopy20220720Mapper;

    @Override
    public List<Message> getMessageList(Long messageId) {
        ArrayList<Message> messageList = new ArrayList<>();
        List<MessageCopy20220720> messageCopyList = messageCopy20220720Mapper.selectListByMessageId(messageId);
        if (messageCopyList.size() > 0){
            messageCopyList.forEach(messageCopy -> {
                Message  message = new Message();
                BeanUtil.copyProperties(messageCopy, message);
                messageList.add(message);
            });
        }
        return messageList;
    }

    @Override
    public List<MessageCopy20220720> getIndexMessageList() {
        return messageCopy20220720Mapper.selectIndexMessageList();
    }

    @Override
    public MessageCopy20220720 getMessageByMessageId(Long messageId) {
        return messageCopy20220720Mapper.selectOneByMessageId(messageId);
    }
}
